import { EncodeRulesService } from './../../../../@core/services/encoderRule/encode-rules.service';
import { Component, Input } from '@angular/core';
import { CascaderItem } from 'ng-devui';
import { stroehouse } from 'src/app/@core/data/storeHouse';
@Component({
  selector: 'app-add-store-house',
  templateUrl: './add-store-house.component.html',
  styleUrls: ['./add-store-house.component.scss']
})
export class AddStoreHouseComponent {
  @Input() data: any;
  options: any;//部门
  stroehouse: stroehouse = {
    warehouseName: '',
    warehouseCategoryId: null,
    isEnabled: false,
    warehouseNum: '',
    isNegative: false,
    qrCode:''
  };//新增仓库
  items: any[] = [
    '启用', '禁用'
  ]
  currentSelectedItem = '启用';
  constructor(private EncodeRulesService: EncodeRulesService) { }
  ngOnInit(): void {
    this.stroehouse.isEnabled = this.currentSelectedItem == '启用' ? true : false
    this.options = this.convertToCascaderItem(this.data.options)
    if (this.data.pathPids) {
      this.stroehouse.warehouseCategoryId = this.data.pathPids[this.data.pathPids.length - 1]
    }
    this.EncodeRulesService.GenerateWarehouseCodeRule('仓库编码','仓库编码').subscribe((res: any) => {
      this.stroehouse.warehouseNum = res
    })
  }
  convertToCascaderItem(data: any[]): CascaderItem[] {
    return data.map(item => {
      let cascaderItem: CascaderItem = {
        label: item.warehouseCategoryName,
        value: item.warehouseCategoryId,
      };
      if (item.subWarehouseCategories) {
        cascaderItem.children = this.convertToCascaderItem(item.subWarehouseCategories);
      }
      return cascaderItem;
    });
  }//转换数据格式为华为库练级菜单的数据格式
  onChanges($event: string | any[]) {
    this.stroehouse.warehouseCategoryId = $event[$event.length - 1]
  }
  valueChange(value: string): void {
    this.stroehouse.isEnabled = value == '启用' ? true : false
  }
}
